#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include <iomanip>
#include <fstream>
#include <string>
#include <string.h>
#include <sstream>
#include <GL/glew.h>
#include <GL/glut.h>
#include <Cg/cg.h>
#include <Cg/cgGL.h>
#include <ctime>
#include <unistd.h>
#include <sys/types.h>


// some Cg variables
CGcontext cgContext = 0;
CGprogram cgProgram = 0;
static GLenum textarget         = GL_TEXTURE_RECTANGLE_ARB;
static GLenum texinternalformat = GL_RGBA_FLOAT32_ATI;

// the texture's on the GPU
//GLuint dataTex; // texture to hold the data
//GLuint convFuncTex; // texture to hold the conv function
GLuint d_textures[3]; // array for generated texture names

static const GLenum texAttachment[] =
{
        GL_COLOR_ATTACHMENT0_EXT,
        GL_COLOR_ATTACHMENT1_EXT,
        GL_COLOR_ATTACHMENT2_EXT
};

// indices in the textures name array
const int readTex     = 0;
const int writeTex    = 1;
const int convFuncTex = 2;

CGprofile cgFragmentProfile;

CGparameter dataHandle     = 0;
CGparameter convFuncHandle = 0;

// number of points in the input data
// (size of the texture to be rendered)
static GLint dataWidth  = 4;
static GLint dataHeight = 4;
static GLint convWidth  = 2;
static GLint convHeight = 2;

//Error codes
static int ERROR_GLEW = -2;
static int ERROR_FBOTEXTURE = -5;
static int ERROR_READBACK  = -10;
static int ERROR_TEXTURE    = -3;


// arrays on the CPU to hold the data and result of GPU calucualtion
float * readTexArr; // texture holding the data to be convolved
float * convFuncTexArr; // texture holding the convolution kernel
float * writeTexArr;  // texture to render to
float * resultArr; // result of convolution


// handle to frame buffer object needed for offscreen redering
GLuint fb;

clock_t start, end;
double elapsed;
time_t rawTime;
struct tm *timeInfo;
